<?php

namespace app\admin\controller;

use think\Controller;
use Util\SysDb;
use think\Db;
class Goodtype extends Controller
{
    public function goodTypelist()
    {
        $page = trim(input('param.pageNo'));
        $limit = trim(input('param.pageSize'));
        $tol = (intval($page) - 1) * $limit;
        $list = DB::name("goods_type")->order("create_time desc")->limit($tol, $limit)->select();
        $this->db = new SysDb();
        $count = $this->db->table('goods_type')->count();
        $data = array();
        array_push($data, $list);
        array_push($data, $count);
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" => $data]));
    }
    public function goodTypeadd()
    {
        $name= trim(input('param.name'));
        $remark = trim(input('param.remark'));
        $this->db = new SysDb();
        $data['name']=$name;
        $data['remark']=$remark;
        $data['status']=1;
        $data['other_type']=1;
        $count = $this->db->table('goods_type')->insert($data);
        if($count){
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" => $data]));
        }
        
    }
    public function goodTypedel()
    {
        $id= trim(input('param.id'));
        $this->db = new SysDb();
        $count = Db::name('goods_type')->where('id', $id)->delete();;
        if($count){
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" => "修改"]));
        }
        
    }
    public function goodTypeupdate()
    {
        $name= trim(input('param.name'));
        $remark = trim(input('param.remark'));
        $id = trim(input('param.id'));
        $this->db = new SysDb();
        $data = $this->db->table('goods_type')->where(['id' => $id])->item();
        $data['name']=$name;
        $data['remark']=$remark;
       
        $admins = $this->db->table('goods_type')->where(['id ' => $id])->update($data);
        if($admins){
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" => $data]));
        }
        
    }
    
}

